package com.practice.Demo6_17.collection;

import com.practice.Demo6_17.Book;
import com.practice.Demo6_17.order;

import java.util.ArrayList;
import java.util.Scanner;

public class Test {
    public static void main(String ars[]){

        ArrayList<Book> list = new ArrayList<>();

        list.add(new Book(1, "java", 33.3, 150));
        list.add(new Book(2, "jsp", 56.6, 150));
        list.add(new Book(3, "vue", 100.25, 150));
        list.add(new Book(4, "html", 20.66, 150));
        list.add(new Book(5, "mysql", 70.00, 150));


        ArrayList<order> ord = new ArrayList<>();

        System.out.println("-----------欢迎进入图书馆-----------");
        System.out.println("书籍展示如下：");

        System.out.println("书籍编号  书籍名称  书籍价格  书籍库存");
        for (Book book : list) {
            System.out.println("  "+book.getBookno()+"      "+book.getName()+"    "
                    +book.getPrice()+"    "+book.getCount());
        }
        int flag=0;
        int num=0;

        Scanner input = new Scanner(System.in);
        while (flag!=-1){

            System.out.println("请输入要购买的书籍编号（int）/退出请输入 -1 ");
            flag = input.nextInt();
            if (flag==-1){
             break;
            }else{
                System.out.println("请输入购买数量：");
                num=input.nextInt();
                order oo = new order();
                oo.name=list.get(flag-1).getName();
                oo.num=num;
                oo.price=list.get(flag-1).getPrice();
                ord.add(oo);
            }

            System.out.println("请继续购买书籍。。。");
        }
        System.out.println("订单总额为："+order.PayTotal(ord));
        for (order o : ord) {
            o.Show();
        }
    }
}
